package cosc617_blackteam;

import java.util.ArrayList;


/**
 * An Iterator of all MenuItems that match the given ingredient
 * @author Laura Semesky
 */
public class IngredientMenuIterator implements I_MenuIterator {

	ArrayList<MenuItem> menu;
	private int index;
	private String ingredient;
	
	public IngredientMenuIterator(ArrayList<MenuItem> menu, String ingredient){
		index = 0;
		this.menu = menu;
		this.ingredient = ingredient;
		
	}
	
	
	@Override
	/*When this returns value of index is where the next matching MenuItem is in the array*/
	public boolean hasNext() {
		
		while(index < menu.size()){
			//checks if menu at current index item has the ingredient given as input to the iterator
			if (menu.get(index).getIngredients().contains(ingredient.trim()))
				return true;
			index++;
		}
		return false;
	}

	@Override
	public MenuItem next() {
		MenuItem output;
		if(hasNext()) //make sure there is a next and index is pointing to it
			output = menu.get(index);
		else
			output = null;
		index++;
		return output;
	}


	@Override
	public void remove() {
		throw new UnsupportedOperationException();
		
	}
	
	

}
